/**
 * 灯光类
 */
 import * as THREE from "./three.js/build/three.module.js";
 import A3Actor from "./A3Actor.js";
import { isNull } from "./A3Common.js";
 
class A3Light extends A3Actor {
  intensity = 1.5;
  color = 0xffffff;
  decay = .1;
  distance = 20;
}
 // 点光源
 class A3PointLight extends A3Light {

  name = "point_light";

  constructor() {

    super();

		const light = new THREE.PointLight( this.color, this.intensity, this.decay );
		light.castShadow = true;
		light.shadow.bias = - 0.005; // reduces self-shadowing on double-sided objects

    this.threeObject = light;

  }

}

class A3SpotLight extends A3Light {

  constructor() {
    super();

    const spotLight = new THREE.SpotLight( this.color, this.intensity );
    spotLight.position.set( 15, 10, 15 );
    spotLight.angle = Math.PI / 6;
    spotLight.penumbra = 0.1;
    spotLight.decay = this.decay;
    spotLight.distance = this.distance;

    spotLight.castShadow = true;
    spotLight.shadow.mapSize.width = 50;
    spotLight.shadow.mapSize.height = 50;
    spotLight.shadow.camera.near = 3;
    spotLight.shadow.camera.far = 50;
    spotLight.shadow.focus = .2;

    this.threeObject = spotLight;
    this.lightHelper = new THREE.SpotLightHelper( spotLight );

  }

  addToWord( scene, world ) {
    super.addToWord( scene, world );
    this.scene.add( this.lightHelper );
  }

  update(){
    super.update();
    // this.threeObject.position.y += 0.01;
    this.lightHelper.update();
  }

}



 export { 
  A3PointLight,
  A3SpotLight,
};